﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;
using DataLayer;

namespace BusinnessLogic
{
    public class MyView
    {
        public User mijnuser(int userid)
        {
            DataSet dts = new DataSet();
            DataLayer.dlmyview myviewuser = new DataLayer.dlmyview();
            dts = myviewuser.getuserfulldetail(userid);

            
            int roleID = int.Parse(dts.Tables[0].Rows[0]["RolesId"].ToString()); //roleID should be a string
            string rolename = dts.Tables[0].Rows[0]["Role"].ToString();
            string login = dts.Tables[0].Rows[0]["Login"].ToString();
            string passwoord = dts.Tables[0].Rows[0]["Passwoord"].ToString();
            string name = dts.Tables[0].Rows[0]["Name"].ToString();
            string firstname = dts.Tables[0].Rows[0]["FirstName"].ToString();
            

            User mijnuser = new User(userid, roleID,login,passwoord,name,firstname,rolename);
            return mijnuser;
        }

        public Tasks taskdetail(int taskid)
        {
            DataSet dts = new DataSet();
            DataLayer.dlonetask taskdetail = new DataLayer.dlonetask();
            dts = taskdetail.getonetask(taskid);


           
            string titel = dts.Tables[0].Rows[0]["Titel"].ToString();
            string description = dts.Tables[0].Rows[0]["Description"].ToString();
            string status = dts.Tables[0].Rows[0]["Status"].ToString();
            string productname = dts.Tables[0].Rows[0]["ProductName"].ToString();
            string username = dts.Tables[0].Rows[0]["UserName"].ToString();
            string userstorytitel = dts.Tables[0].Rows[0]["UserStoryTitel"].ToString();
            string sprinttitel = dts.Tables[0].Rows[0]["SprintTitel"].ToString();
            string firstname = dts.Tables[0].Rows[0]["FirstName"].ToString();
            string name = dts.Tables[0].Rows[0]["Name"].ToString();
            string impedimenttitel = dts.Tables[0].Rows[0]["ImpedimentTitel"].ToString();
            int estimatedworkload = int.Parse(dts.Tables[0].Rows[0]["EstimatedWorkload"].ToString());
            int realworkedtime = int.Parse(dts.Tables[0].Rows[0]["ProductName"].ToString());


            Tasks mijntask = new Tasks(taskid, titel, description, status, userstorytitel, sprinttitel, productname, firstname, name, impedimenttitel, estimatedworkload, realworkedtime);
            return mijntask;

        }

        public List<Tasks> getmytasks(int userid)
        {

            List<Tasks> mytasks = new List<Tasks>();
            DataSet dts = new DataSet();
            dlmyview dlgetview = new dlmyview();

            dts = dlgetview.getusertasks(userid);

            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                int taskid = int.Parse(dts.Tables[0].Rows[i]["TaskId"].ToString());
                string taskname = dts.Tables[0].Rows[i]["Titel"].ToString();
                string taskstatus = dts.Tables[0].Rows[i]["Status"].ToString();
                string sprinttitel = dts.Tables[0].Rows[i]["SprintTitel"].ToString();
                DateTime sprintduedate = (DateTime)dts.Tables[0].Rows[i]["SprintDueDate"];
                string teamname = dts.Tables[0].Rows[i]["TeamName"].ToString();
                string userstorytitel = dts.Tables[0].Rows[i]["UserStoryTitel"].ToString();

                Tasks atask = new Tasks(taskid,taskname,taskstatus,sprintduedate,sprinttitel,teamname,userstorytitel);
                mytasks.Add(atask);
            }

            return mytasks;
        }

        //function to retrieve the teams of a user
        public List<string> UserTeamRetriever(int userid)
        {
            List<string> userteams = new List<string>();
            DataSet dts = new DataSet();
            dlmyview dlgetteams = new dlmyview();
            dts = dlgetteams.getuserteams(userid);

            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                userteams.Add(dts.Tables[0].Rows[i]["Name"].ToString());
            }
            return userteams;

        }
    }
}
